package com.wontube.smr.web.controller.i18n;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.client.remote.Remoting;
import com.wontube.smr.web.client.IFeedbackHandler;
import com.wontube.smr.web.client.model.vo.FeedbackItems;


/**
 * @author tanggf(2012-5-5)
 *
 */
@Controller
@RequestMapping("/world/feedback")
public class I18nFeedbackController {
	private final static int PAGE_SIZE = 10;
	
	@RequestMapping("")
	public void f2(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/world/feedback/");		
	}
	
	@RequestMapping("/")
	public ModelAndView feedbackHome(){
		return new ModelAndView("i18n/about/feedback/feedback_index");
	}
		
	/**
	 * list user feedbacks
	 * @param page
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list_feedbacks(@RequestParam(value="page", defaultValue="1") int page){		
		ModelAndView mv = new ModelAndView("i18n/about/feedback/feedback_list");
		Remoting<IFeedbackHandler> remoting = new Remoting<IFeedbackHandler>();
		IFeedbackHandler handler = remoting.createService(IFeedbackHandler.class);
		FeedbackItems items = handler.listFeedbacks(new PagenateInfo(page, PAGE_SIZE),1);//1表示国际版的feedback
		mv.addObject("feedbackItems", items);
		mv.addObject("page", page);
		return mv;
	}
}
